package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqLockNet;
import com.wtwd.campus.entity.Plmn;
import com.wtwd.campus.service.InjectFeignService;

import java.util.ArrayList;
import java.util.List;

/**
 * @author mjy
 * @date 2022/12/29
 * @description
 */
public class SetLockNetReceiver implements Receiver {
    @Override
    public String parseMessage(String data) {
//        *TJ,IMEI,LOCKNET,seq,switch,groupNum,mcc,mnc......,tracker _status#
        String[] split = data.split(",");
        String imei = split[1];
        String commandNumber = split[3];
        int flag = Integer.valueOf(split[4]);
        int groupNum = Integer.valueOf(split[5]);
        List<Plmn> plmns = new ArrayList<>();
        for (int i = 1; i <= groupNum; i++) {
            String mcc = split[5 + 2 * (i - 1) + i];
            String mnc = split[6 + 2 * (i - 1) + i];
            Plmn plmn = new Plmn();
            plmn.setMcc(mcc);
            plmn.setMnc(mnc);
            plmns.add(plmn);
        }
        MqLockNet lockNet = new MqLockNet();
        lockNet.setImei(imei);
        lockNet.setCommandNumber(commandNumber);
        lockNet.setGroupNum(groupNum);
        lockNet.setFlag(flag);
        lockNet.setPlmns(plmns);
        InjectFeignService.getIrmFeignClientService().setLockNetReceiver(lockNet);
        return imei;
    }
}
